import request from '@/utils/request'
// import qs from 'qs'

// 带宽管理

// 删除带宽
export function delBandWidth (params) {
  var data = fromData(params)
  return request({
    url: '/bandwidth/delBandWidth',
    method: 'post',
    data
  })
}

// 删除接口
export function delInterface (params) {
  var data = fromData(params)
  return request({
    url: '/bandwidth/delInterface',
    method: 'post',
    data
  })
}

// 删除规则
export function delRule (params) {
  var data = fromData(params)
  return request({
    url: '/bandwidth/delRule',
    method: 'post',
    data
  })
}

// 添加带宽分类
export function addBandWidth (params) {
  var data = fromData(params)
  return request({
    url: '/bandwidth/addBandWidth',
    method: 'post',
    data
  })
}

// 添加接口
export function addInterface (params) {
  var data = fromData(params)
  return request({
    url: '/bandwidth/addInterface',
    method: 'post',
    data
  })
}

// 编辑接口
export function editInterface (params) {
  var data = fromData(params)
  return request({
    url: '/bandwidth/editInterface',
    method: 'post',
    data
  })
}

// 添加规则
export function addRule (params) {
  var data = fromData(params)
  return request({
    url: '/bandwidth/addRule',
    method: 'post',
    data
  })
}

// 编辑带宽分类
export function editBandWidth (params) {
  var data = fromData(params)
  return request({
    url: '/bandwidth/editBandWidth',
    method: 'post',
    data
  })
}

// 编辑规则
export function editRule (params) {
  var data = fromData(params)
  return request({
    url: '/bandwidth/editRule',
    method: 'post',
    data
  })
}

// 获取带宽分类信息
export function getBandWidthInfo (params) {
  var data = fromData(params)
  return request({
    url: '/bandwidth/getBandWidthInfo',
    method: 'post',
    data
  })
}

// 获取接口列表
export function getBandWidthArray (params) {
  var data = fromData(params)
  return request({
    url: '/bandwidth/getBandWidthArray',
    method: 'post',
    data
  })
}

// 获取规则信息
export function getRuleInfo (params) {
  var data = fromData(params)
  return request({
    url: '/bandwidth/getRuleInfo',
    method: 'post',
    data
  })
}

// function fromData (params) {
//   var data = qs.stringify(params)
//   return data
// }

function fromData (params) {
  let formData = new FormData()
  for (const it in params) {
    if (!Object.is(params[it], null) && !Object.is(params[it], '')) {
      formData.append(it, params[it])
    }
  }
  return formData
}
